package jsen.tool.ddd.adapter.infrastructure.specification.demo.spec.send;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;
import jsen.tool.ddd.adapter.infrastructure.specification.base.SpecContext;
import jsen.tool.ddd.adapter.infrastructure.specification.demo.SendMethod;
import org.apache.commons.lang3.StringUtils;

/**
 * @author jsen
 * @date 2021/10/6
 * <p>
 * 名字和别名不能相同
 */
class SendMethodNameSpec implements ISpecification<SendMethod> {

    @Override
    public boolean isSatisfiedBy(SpecContext<SendMethod> t) {
        SendMethod info = t.getData();
        boolean isSame = StringUtils.equals(info.getName(), info.getAlias());
        if (isSame) {
            t.addError("SendMethodNameSpec", "名字和别名不能一样");
        }
        return !isSame;
    }
}
